﻿using System.Reflection;

namespace Loong.Admin.Reflection
{
    public static class ReflectionHelper
    {
        public static object? GetFieldValue(Type type, string fieldName)
        {
            var fieldInfo = type.GetField(fieldName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            if (fieldInfo == null) return null;

            return fieldInfo.GetValue(null);
        }

        public static object? GetFieldValue(object obj, string fieldName)
        {
            var type = obj.GetType();

            var fieldInfo = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            if (fieldInfo == null) return null;

            return fieldInfo.GetValue(obj);
        }
    }
}
